package com.huarui.sale.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.dao.impl.BaseDaoImpl;

import com.huarui.sale.dao.ISaleDao;
import com.huarui.sale.model.Sale;

public class SaleDao extends BaseDaoImpl implements ISaleDao {

	@Override
	public Integer getSaleCount(Map<String, Object> queryMap) {
		return (Integer) getSqlMapClientTemplate().queryForObject(
				namespace + ".getSalePageCount", queryMap);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Sale> getSalePage(Map<String, Object> queryMap) {

		return getSqlMapClientTemplate().queryForList(
				namespace + ".getSalePage", queryMap);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Object>> getSaleIdPage(Map<String, Object> queryMap) {

		return getSqlMapClientTemplate().queryForList(
				namespace + ".getSaleIdPage", queryMap);
	}

	@Override
	public Sale getSaleByCodeAndCompanyId(String code, int companyId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("codeOfSeller", code);
		map.put("companyId", companyId);
		return (Sale) getSqlMapClientTemplate().queryForObject(
				namespace + ".getSaleByCodeAndCompanyId", map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Sale> getSaleByConditions(Map<String, Object> map) {
		return getSqlMapClientTemplate().queryForList(namespace+".getSaleByConditions", map);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Map> getSaleForMapByConditions(Map queryMap) {		
		return getSqlMapClientTemplate().queryForList(namespace+".getSaleForMapByConditions", queryMap);
	}

	@Override
	public Sale getSaleById(Map<String, Object> map) {		
		return (Sale) getSqlMapClientTemplate().queryForObject(namespace+".getSaleById", map);
	}

	@Override
	public boolean updateSaleCurrentorId(Map<String, Object> map) {
		return getSqlMapClientTemplate().update(namespace+".updateSaleCurrentorId", map)==1;
		
	}

	@Override
	public Integer getSaleIdByOrdersId(Integer orderId) {
		
		return (Integer) getSqlMapClientTemplate().queryForObject(namespace+".getSaleIdByOrdersId", orderId);
	}

}
